/**
 * 
 */
package com.cqan.tuan.parser;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.stereotype.Component;

import com.cqan.exception.AppException;
import com.cqan.tuan.entity.BaseEntity;
import com.cqan.tuan.entity.City;
import com.google.common.collect.Lists;

/**
 * @author slaton
 *
 * 2012-12-1上午11:47:30 created
 */
@Component
public class CityXmlParser extends XmlParser {

	/**
	 * 解析美团网城市地址
	 * http://www.meituan.com/api/v1/divisions
	 */
	@Override
	@SuppressWarnings("unchecked")
	List<BaseEntity> analyze(Document doc)throws AppException {
		List<BaseEntity> citys = Lists.newArrayList();
		try {
			List<Element> elements = doc.selectNodes("cities/city");
			if (elements!=null&&elements.size()>0) {
				for (Element e : elements) {
					City city = new City();
					city.setName(e.elementText("name"));
					citys.add(city);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return citys;
	}

}
